package main

import "fmt"

func main() {
	//定义切片
	//make([]T, length, capacity)
	s := []int{1, 2, 3}
	fmt.Println(len(s), cap(s))

	//缺省endIndex时将表示一直到arr的最后一个元素
	fmt.Println(s[1:])

	//缺省startIndex时将表示从arr的第一个元素开始
	fmt.Println(s[:2])

	var numbers = make([]int, 3, 5)

	printSlice(numbers)

	for i := 0; i < 3; i++ {
		numbers = append(numbers, i)
	}
	printSlice(numbers)

	for i := 0; i < 20; i++ {
		numbers = append(numbers, i)
	}
	printSlice(numbers)
}

func printSlice(numbers []int) {
	fmt.Printf("len=%d cap=%d slice=%v\n", len(numbers), cap(numbers), numbers)

}
